package java8Up;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Fang Ruichuan
 * @date 2022-09-08 9:22
 */

public class DateDemo {

    public static void main(String[] args) {
        showYearAndMonth();
        System.out.println("================");
        Calendar birth = Calendar.getInstance();
        birth.set(1975, Calendar.MAY, 26);
        Calendar now = Calendar.getInstance();
        System.out.println(daysBetween(birth, now));
        System.out.println(daysBetween(birth, now));
    }

    private static void showYearAndMonth() {
        Date date = new Date(2012, 1, 1);
        System.out.println(date);
    }

    private static void showCalendar() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(2013, 8, 2);
    }

    // 计算两个日期之间的天数
    private static long daysBetween(Calendar begin, Calendar end) {
        long daysBetween = 0;
        while (begin.before(end)) {
            begin.add(Calendar.DAY_OF_MONTH, 1);
            daysBetween++;
        }
        return daysBetween;
    }

}
